/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beans.forms;

import beans.LoginBean;
import beans.MessagesController;
import datamodel.SystemCustomer;
import datamodel.Ticket;
import ejb.CategoryManager;
import ejb.TicketManager;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;

/**
 *
 * @author Administrator
 */
@ManagedBean
@RequestScoped
public class NewTicketForm {

    private String title;
    private String content;
    private long category;
    @ManagedProperty(value = "#{login}")
    private LoginBean login;

    @EJB
    private TicketManager tm;
    
    @EJB
    private CategoryManager cm;
    
    /**
     * @return the title
     */
    public String getTitle() {
        return title;
    }

    /**
     * @param title the title to set
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * @return the content
     */
    public String getContent() {
        return content;
    }

    /**
     * @param content the content to set
     */
    public void setContent(String content) {
        this.content = content;
    }

    /**
     * @return the category
     */
    public long getCategory() {
        return category;
    }

    /**
     * @param category the category to set
     */
    public void setCategory(long category) {
        this.category = category;
    }

    public String saveTicket() {
        Ticket t = new Ticket(title, content, cm.getCategory(category), (SystemCustomer)login.getLoggedUser());
        tm.saveTicket(t);
        return "ticketList?faces-redirect=true";
    }

    /**
     * @param login the login to set
     */
    public void setLogin(LoginBean login) {
        this.login = login;
    }
}
